<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body {
            height: 3000px;
        }

        .backtop {
            width: 30px;
            padding: 10px 4px;
            text-align: center;
            position: fixed;
            bottom: 100px;
            right: 10px;
            box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.1);
            display: none;
            cursor: pointer;
        }
    </style>
</head>

<body>
    <div class="backtop">
        返回顶部
    </div>
    <script>
        var backtop = document.querySelector('.backtop')
        // 注册scroll滚动事件
        window.onscroll = function () {
            // console.log(window.scrollY,'window.scrollY');
            
            if (window.scrollY >= 1000) {
                // 显示返回页面顶部按钮
                backtop.style.display = 'block'
            }else{
                backtop.style.display='none'
            }
        }
    </script>
</body>

</html>